package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// Photo holds the schema definition for the Photo entity.
type Photo struct {
	ent.Schema
}

// Fields of the Photo.
func (Photo) Fields() []ent.Field {
	return []ent.Field{
		field.String("url").
			NotEmpty().
			Comment("图片地址"),
		field.Text("description").
			Optional().
			Comment("描述"),
		field.Int64("upload_user_id").
			Comment("上传者ID"),
		field.Time("deleted_at").
			Optional().
			Nillable().
			Comment("软删除时间"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the Photo.
func (Photo) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("uploader", User.Type).
			Ref("photos").
			Field("upload_user_id").
			Unique().
			Required(),
	}
}
